// @ts-ignore
/* eslint-disable */
import { request } from '@umijs/max';

/** addUserDataStructure POST /api/user_data_structure/add */
export async function addUserDataStructureUsingPOST(
  params: API.UserDataStructureAddRequest,
  body: {},
  file?: File,
  options?: { [key: string]: any },
) {
  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      formData.append(
        ele,
        typeof item === 'object' && !(item instanceof File) ? JSON.stringify(item) : item,
      );
    }
  });

  return request<API.BaseResponseLong_>('/api/user_data_structure/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/octet-stream',
    },
    params: {
      ...params,
    },
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}

/** deleteUserDataStructure POST /api/user_data_structure/delete */
export async function deleteUserDataStructureUsingPOST(
  body: API.DeleteRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseBoolean_>('/api/user_data_structure/delete', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** getUserDataStructureById GET /api/user_data_structure/get */
export async function getUserDataStructureByIdUsingGET(
  // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
  params: API.getUserDataStructureByIdUsingGETParams,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseUserDataStructure_>('/api/user_data_structure/get', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** listUserDataStructure POST /api/user_data_structure/list */
export async function listUserDataStructureUsingPOST(
  body: API.UserDataStructureQueryRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseListUserDataStructure_>('/api/user_data_structure/list', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** listUserDataStructureByPage POST /api/user_data_structure/list/page */
export async function listUserDataStructureByPageUsingPOST(
  body: API.UserDataStructureQueryRequest,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponsePageUserDataStructure_>('/api/user_data_structure/list/page', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

export async function simpleQueryUsingPOST(
  body: API.SimpleQuery,
  options?: { [key: string]: any },
) {
  return request<API.BaseResponseString_>('/api/user_data_structure/query', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** updateUserDataStructure POST /api/user_data_structure/update */
export async function updateUserDataStructureUsingPOST(
  params: API.UserDataStructureUpdateRequest,
  body: {},
  file?: File,
  options?: { [key: string]: any },
) {

  const formData = new FormData();

  if (file) {
    formData.append('file', file);
  }

  Object.keys(body).forEach((ele) => {
    const item = (body as any)[ele];

    if (item !== undefined && item !== null) {
      formData.append(
        ele,
        typeof item === 'object' && !(item instanceof File) ? JSON.stringify(item) : item,
      );
    }
  });

  return request<API.BaseResponseBoolean_>('/api/user_data_structure/update', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/octet-stream',
    },
    params: {
      ...params,
    },
    data: formData,
    requestType: 'form',
    ...(options || {}),
  });
}
